package br.net.woodstock.tickettoride.web.jsf.security.common;

import br.net.woodstock.tickettoride.orm.User;
import br.net.woodstock.tickettoride.orm.UserType;
import br.net.woodstock.tickettoride.web.jsf.TTRBean;

public abstract class AbstractSessionBean extends TTRBean {

	private static final long	serialVersionUID	= -1842899436116476694L;

	public AbstractSessionBean() {
		super();
	}

	public User getUser() {
		return JSFSecurityUtils.getSessionUser();
	}

	public String getRole() {
		User user = JSFSecurityUtils.getSessionUser();
		if (user != null) {
			return user.getType().name();
		}
		return null;
	}

	public boolean isLoggedIn() {
		return JSFSecurityUtils.isLoggedIn();
	}

	public boolean isInRoleAdministrator() {
		return JSFSecurityUtils.isUserInRole(UserType.ADMINISTRATOR.name());
	}

	public boolean isInRoleManager() {
		return JSFSecurityUtils.isUserInRole(UserType.MANAGER.name());
	}

	public boolean isInRoleUser() {
		return JSFSecurityUtils.isUserInRole(UserType.USER.name());
	}

}
